import { defineStore } from "pinia";
import { useRequest } from "alova";
import { Names } from "./store-names";
import type { TUserModel } from "@/stores/typings/user";
import { getUserById } from "@/api/user";

const useUserStore = defineStore(Names.USER, {
  state() {
      return {
        user: <TUserModel>{}
      }
  },

  getters: {

  },
  actions: {
    getUserById(id: string, fn: Function) {
      const { onSuccess } = useRequest(getUserById(id));
      onSuccess((res) => {
        if (res.data) {
          console.log('res.data', res.data)
          // this.user = res.data
          fn && fn(res.data);
        }
      });
    },
  }
})

export default useUserStore
